import java.lang.reflect.Field;
import java.util.Objects;

/**
 * 简单测试
 * Created by Administrator on 2017/9/19-23:13.
 */
public class TT {

    public static void main(String[] args) {
        //测试java date和时间戳之间的转换
/*        String a = "I think very much";
        TimeStamp ts = TimeStamp.getCurrentTime();
        System.out.println(ts.toDateString());
        System.out.println(ts);
        String format = new SimpleDateFormat("EEE, MMM dd yyyy HH:mm:ss.SSS", Locale.CHINA).format(ts.getTime());
        System.out.println(format);
        System.out.println(Long.toHexString(ts.getDate().getTime()));*/

        //测试枚举
/*        System.out.println(color.RED);
        System.out.println(color.GREEN);
        System.out.println(color.BLUE);*/

        //测试两个方法的区别
//        System.out.println(StringUtils.isNotBlank(" "));
//        System.out.println(StringUtils.isNotEmpty(" "));

        //测试java的读取.properties文件的方法
/*        ResourceBundle rb = ResourceBundle.getBundle("datasource");
        Enumeration<String> keys = rb.getKeys();
        while (keys.hasMoreElements()) {
            String s = keys.nextElement();
            System.out.println(s + "=" + rb.getString(s));
        }*/

        //测试山吹圣痕200抽最后一抽才抽到的概率.
/*        double a = 1.0;
        for (int i = 0; i < 200; i++) {
            a = a * ((199.0 - i) / (200.0 - i));
            System.out.println(a);
        }
        System.out.println(a);*/

        //测试BigDecimal
/*        BigDecimal b0 = new BigDecimal(0.05);
        BigDecimal b1 = new BigDecimal(0.01);
        BigDecimal b2 = new BigDecimal("0.01");
        BigDecimal b3 = new BigDecimal("0.05");
        System.out.println(b0.add(b1));
        System.out.println(b2.add(b3.add(b2)));*/

        //通过提供的字符串反射类型在控制台输出Vo对象自动封装原始对象相同字段的代码
        try {
            getCode("com.mmall.pojo.OrderItem", "com.mmall.vo.OrderItemVo");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    //我想写一个输入原始对象类型和VO对象类型,可以自动输入封装代码的方法
    public static void getCode(String original, String Vo) throws ClassNotFoundException {
        Field[] originalFields = Class.forName(original).getDeclaredFields();
        Field[] fields = Class.forName(Vo).getDeclaredFields();
//        for (Field originalField : originalFields) {
//            System.out.println(originalField.getName());
//        }
//        System.out.println("========================");
//        for (Field originalField : fields) {
//            System.out.println(originalField.getName());
//        }
        //orderVo.setPostage(order.getPostage());
        for (Field field : fields) {
            boolean temp = true;
            for (Field originalField : originalFields) {
                if (Objects.equals(field.getName(), originalField.getName())) {
                    System.out.println(Lower1st(Vo.split("\\.")[Vo.split("\\.").length - 1]) + ".set" + Upper1st(field.getName()) + "("
                            + Lower1st(original.split("\\.")[original.split("\\.").length - 1]) + ".get" + Upper1st(originalField.getName()) + "());");
                    temp = false;
                }
            }
            if (temp) System.out.println("||||缺少" + field.getName() + "字段");
        }
    }

    //将传入小写字符串的首字母大写
    public static String Upper1st(String s) {
        return s.substring(0, 1).toUpperCase() + s.substring(1);
    }

    public static String Lower1st(String s) {
        return s.substring(0, 1).toLowerCase() + s.substring(1);
    }

}

enum color {RED, GREEN, BLUE}



